using Test

@test Symbol(:a, :(=), :1, :+, :2, :*, :3) == Symbol("a=1+2*3")
@test Symbol(:a, :(=), :2, :*, :3, :+, :1) == Symbol("a=2*3+1")
@test Symbol("(", :a, :+, :1, ")", :*, "(", :2,  :+, :3, ")") == Symbol("(a+1)*(2+3)")
@test Symbol("(", :a,:var, :+, :10, ")", :/, "(", :2,  :+, 15, ")") == Symbol("(avar+10)/(2+15)")

@test :[10,20,30] == :([10, 20, 30])
@test :(10,20,30) == :((10, 20, 30))
@test :(Set([1,2,3,4])) == :(Set([1, 2, 3, 4]))

a = :foo
@test a == :foo

b = :[]
@test b == :([])

# 10.2
b = :(1+2)
@test b == :(1 + 2)
@test typeof(b) == Expr
dump(b)
@test b.head == :call
@test b.args == [:+, 1, 2]
@test eval(b) == 3

x = :(a = (1+2)*3)
@test eval(x) == 9 == a

y1 = Expr(:call, :+, :1, :2)
@test y1 == :(1 + 2)
@test eval(y1) == 3

y2 = Expr(:call, :*, y1, :3)
@test y2 == :((1 + 2) * 3)
y3 = Expr(:(=), :a, y2)
@test y3 == :(a = (1 + 2) * 3)
@test typeof(y3) == Expr

@test y3 == x
@test eval(y3) == 9 == a


x = 1;
c = Expr(:call, :+, x, (1+1))
@test c == :(1 + 2)

c = :($x+$(1+1))
@test c == :(1 + 2)

dump(:(a = (1+2)*3))

Meta.show_sexpr(:(a = (1+2)*3))
println()

@test string(:(a = (1+2)*3)) == "a = (1 + 2) * 3"

@test Meta.parse("1+2") == :(1 + 2)
@test Meta.parse("a=(1+2)*3") == :(a = (1 + 2) * 3)

x = 1;
y = 2;
swap = begin            # 交换x与y中数值的复合表达式
    println(x, ", ", y)
    z = x
    global x = y
    global y = z
end;

@test x == 2
@test y == 1
swap;
@test x == 1
@test y == 2